package com.xuya.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xuya.dao.ProductDao;
import com.xuya.entity.Adminer;
import com.xuya.entity.Product;

public class UpdateServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		Adminer adminer = (Adminer) session.getAttribute("user");
		if(adminer == null){
			resp.sendRedirect("index.jsp?code=10001");
			return;
		}
		String id = req.getParameter("id"); 
	  	ProductDao pdao = new ProductDao(); 
	  	Product p = pdao.findProduct(Integer.valueOf(id));
	  	if(p== null){
	  		resp.sendRedirect("main.jsp?code=10006");
			return;
	  	}else{
	  		req.setAttribute("product",p);
	  		req.getRequestDispatcher("edit.jsp").forward(req, resp);
	  	}
	}
	
}
